home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Oberon⁄F™ 1.2 / Preinstalled version / Std / Docu / Folds (.txt) < prev    next >
Encoding:
Oberon Document  |  1995-08-09  |  18.7 KB  |  307 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. Helvetica
  23. StdFolds.FoldDesc
  24. Arial
  25. This is a piece of text enclosed by folds in expanded mode
  26. Arial
  27. Arial
  28. NEW(n); n.id := id; n.name := name; n.value := value;
  29. Arial
  30. h := list; p := NIL;
  31.         WHILE (h # NIL) & (h.id <= id) DO p := h; h := h.next END;
  32. Arial
  33. Arial
  34. p.next := n
  35. Arial
  36. list := n
  37. IF p # NIL THEN 
  38. insert between p and h
  39.         ELSE 
  40. insert at beginning
  41.         END;
  42.         n.next := h
  43. VAR n, h, p: Node;
  44.     BEGIN
  45. create new node n
  46. search position in list
  47. insert in list
  48.     END Enter;
  49. Helvetica
  50. FormViews.StdViewDesc
  51. FormViews.ViewDesc
  52. FormModels.StdModelDesc
  53. FormModels.ModelDesc
  54. Controls.GroupDesc
  55. Controls.ControlDesc
  56. Label
  57. Controls.CheckBoxDesc
  58. StdFolds.foldData.nested
  59.  Nested
  60. Controls.FieldDesc
  61. StdFolds.foldData.label
  62. Controls.PushButtonDesc
  63. StdFolds.foldData.expand
  64. Expand
  65. StdCmds.CloseDialog
  66. Cancel
  67. StdFolds.foldData.collapse
  68. Collapse
  69. StdFolds.foldData.selective
  70.  Selective Fold
  71. StdFolds.LabelCheckNotify
  72. FormControllers.StdControllerDesc
  73. FormControllers.ControllerDesc
  74. Containers.ControllerDesc
  75. Controllers.ControllerDesc
  76. TextRulers.StdRulerDesc
  77. TextRulers.RulerDesc
  78. Views.ViewDesc
  79. Stores.StoreDesc
  80. TextRulers.StdStyleDesc
  81. TextRulers.StyleDesc
  82. Models.ModelDesc
  83. Stores.ElemDesc
  84. TextRulers.AttributesDesc
  85. FormViews.StdViewDesc
  86. FormViews.ViewDesc
  87. Containers.ViewDesc
  88. FormModels.StdModelDesc
  89. FormModels.ModelDesc
  90. Containers.ModelDesc
  91. Controls.FieldDesc
  92. Controls.ControlDesc
  93. StdFolds.lblData.label
  94. Controls.PushButtonDesc
  95. StdFolds.lblData.set
  96. StdCmds.CloseDialog
  97. Cancel
  98. Controls.CaptionDesc
  99. StdFolds.lblData.label
  100. Label
  101. FormControllers.StdControllerDesc
  102. FormControllers.ControllerDesc
  103. Containers.ControllerDesc
  104. TextModels.AttributesDesc
  105. Helvetica
  106. StdFolds
  107. DEFINITION StdFolds;
  108.     IMPORT TextModels, Domains, Views, Properties, Dialog;
  109.     CONST
  110.         collapsed = 0; expanded = 1;
  111.         left = 0; right = 1;
  112.         label = 0;
  113.     TYPE
  114.         Label = ARRAY 32 OF CHAR;
  115.         Fold = POINTER TO FoldDesc;
  116.         FoldDesc = RECORD (Views.ViewDesc)
  117.             kind-, state-: INTEGER;
  118.             label-: Label
  119.         END;
  120.         Property = POINTER TO PropertyDesc;
  121.         PropertyDesc = RECORD (Properties.PropertyDesc)
  122.             label: Label
  123.         END;    
  124.         foldData: RECORD (Dialog.Interactor)
  125.             nested, selective: BOOLEAN;
  126.             label: Label;
  127.             expand, collapse: PROCEDURE
  128.         END;
  129.         labelData: RECORD (Dialog.Interactor)
  130.             label: Label;
  131.             set: PROCEDURE
  132.         END;
  133.     PROCEDURE  Matching (fold: Fold): Fold;
  134.     PROCEDURE  HiddenText (fold: Fold): TextModels.Model;
  135.     PROCEDURE  Flip (fold: Fold);
  136.     PROCEDURE  FlipNested (fold: Fold);
  137.     PROCEDURE  CollapseFolds (text: TextModels.Model; nested: BOOLEAN; label: ARRAY OF CHAR);
  138.     PROCEDURE  ExpandFolds (text: TextModels.Model; nested: BOOLEAN; label: ARRAY OF CHAR);
  139.     PROCEDURE  Collapse;
  140.     PROCEDURE  Expand;
  141.     PROCEDURE  ZoomOut;
  142.     PROCEDURE  ZoomIn;
  143.     PROCEDURE  CollapseLabel;
  144.     PROCEDURE  ExpandLabel;
  145.     PROCEDURE  LabelCheckNotify (op, from, to: LONGINT);
  146.     PROCEDURE  LabelGuard (VAR par: Dialog.Par);
  147.     PROCEDURE  InitLabelDialog;
  148.     PROCEDURE  SetLabelGuard (VAR par: Dialog.Par);
  149.     PROCEDURE  SetLabel;
  150.     PROCEDURE  Overlaps (text: TextModels.Model; beg, end: LONGINT): BOOLEAN;
  151.     PROCEDURE  CreateGuard (VAR par: Dialog.Par);
  152.     PROCEDURE  Insert (text: TextModels.Model; beg, end: LONGINT; state: LONGINT);
  153.     PROCEDURE  Create (state: LONGINT);
  154.     PROCEDURE  Init (fold: Fold; kind, state: INTEGER; label: Label; hidden: TextModels.Model);
  155. END StdFolds.
  156. Fold views, also called folds, are views that always appear in pairs. They are only meaningful when embedded in texts. A pair, called the left and right fold, brackets a stretch of text and represent a second piece of text that is hidden. By clicking at a fold with the mouse, the stretch of text between the left and right fold is replaced with the hidden text, and the text that originally appeared between the folds becomes the hidden text. Clicking a second time at the same fold restores the original state. Because the primary use of folds is to hide longer stretches of text and replace them with a usually much shorter placeholder, a fold is said to be either in expanded or collapsed state. Try it!
  157. text between collapsed folds
  158. Folds can be nested, but the stretch between one pair of folds must not partially overlap another. Hierarchically nested folds are often used in program texts. By hiding a sequence of statements and writing a short comment between the collapsed folds, the resulting program text can be explored interactively in a top-down manner. Try it with this example!
  159.     PROCEDURE Enter (id: LONGINT; name: TextMappers.String; value: REAL);
  160. enter a new value into the list
  161. Instead of clicking manually through a deep hierarchy of folds, you can hold down the modifier key while clicking at the fold. This expands or collapses a fold and all nested folds.
  162. The following menu entries operate on folds. Create Fold in menu Tools inserts a new pair of folds in the focus text. The current text selection in the focus text will be bracketed by the newly inserted folds. Expand All in menu Tools expands all folds in the focus text. Similarly, Collapse All collapses all folds in the focus text. Fold... in menu Tools opens a dialog box that lets you qualify which folds in the focus text to collapse or expand (see fig. 1, below). If the check box Nested is checked, all nested folds are collapsed or expanded. This corresponds to choosing Expand All or Collapse All fro the menu. If Nested is not checked, only the outermost folds in the nesting hierarchy are affected. For example, when you click Expand, only the outermost folds in the nesting hierarchy that are collapsed will be expanded. Checking Selective Fold enables the text entry field above the check box. By specifying a label value in this field, the set of folds affected can be restricted to those that have a label property matching the given string.
  163. Fig. 1: The dialog box opened by menu item Fold...
  164. Set Label... from menu Tools opens a dialog box to inspect and set the label property of a pair of folds (see fig. 2, below). The text field contains the label property value of the first fold in the current selection of the focus text. The entry field is diabled if no fold is contained in the text selection. The Set button sets the label property of the first fold contained in the text selection of the focus text. If no fold is contained in the selection when Set is pressed, the entry field will be disabled.
  165. Fig. 2: The dialog box opened by menu item Set Label...
  166. To describe the pre- and postconditions of procedures exported from StdFolds, we use the following pseudo-procedures.
  167. Pos(f)    designates the position of the fold view f in its hosting text.
  168. 0 <= Pos(f) < text.Length().
  169. Stretch(p1, p2)     stands for the text stretch [p1, p2) if p1 < p2 holds, or if p2 <= p1, then it denotes the text stretch [p2, p1).
  170. Flipped(f)     denotes the fold f in its dual, "flipped" state.
  171. f.state = collapsed <=> Flipped(f).state = expanded.
  172. CONST left, right
  173. Possible values of field Fold.kind.
  174. CONST collapsed, expanded
  175. Possible values of field Fold.state.
  176. CONST label
  177. Possible value of fields Property.valid and Property.known.
  178. TYPE Label
  179. String type for label property values.
  180. TYPE Fold
  181. Extension, Leaf
  182. kind-: INTEGER
  183. Possible values are left and right. Determines whether the view is the left or right element of a pair.
  184. state-: INTEGER
  185. Possible values are collapsed and expanded. Determines whether the fold view currently is in expanded or collapsed state.
  186. label-: Label
  187. A string indicating the label property of the fold. If the fold has no label associated with it, label = "" holds.
  188. TYPE Property
  189. Extension
  190. Used to poll and set the label property of fold views.
  191. label: Label
  192. Contains a string if label IN Property.valid.
  193. VAR foldData
  194. An interactor to selectively collapse and expand the fold views contained in the focus text.
  195. PROCEDURE Matching (fold: Fold): Fold
  196. Returns the matching fold view to fold, or NIL if none can be found.
  197. 20        fold # NIL
  198. ~(fold.context IS TextModels.Context)
  199.     result = NIL
  200. fold.context IS TextModels.Context
  201.     (fold.kind = left) & (result.kind = right) & Pos(fold) < Pos(result)
  202.             & (For all folds f with Pos(fold) < Pos(f) < Pos(result):
  203.                     (Matching(f) # NIL) & (Pos(fold) < Pos(Matching(f) < Pos(result))
  204.     OR (fold.kind = right) & (result.kind = left) & (Pos(fold) > Pos(result)
  205.             & (For all folds f with Pos(result) < Pos(f) < Pos(fold): 
  206.                     (Matching(f) # NIL) & (Pos(result) < Pos(Matching(f) < Pos(fold))
  207.     OR result = NIL
  208. PROCEDURE HiddenText (fold: Fold): TextModels.Model
  209. Returns the text stretch that is currently hidden by the pair (fold, Matching(fold)). The text should not be modified. If the hidden text stretch is of length zero, NIL is returned.
  210. 20        fold # NIL
  211. Matching(fold) # NIL
  212.     [ let p1 := Pos(Flipped(fold)), p2 := Pos(Matching(Flipped(fold))) ]
  213.     ABS(p2 - p1) = 1  =>  result = NIL
  214.     ABS(p2 - p1) > 1  =>  result is Stretch(p1, p2)
  215. Matching(fold) = NIL
  216.     result = NIL
  217. PROCEDURE Flip (fold: Fold);
  218. Changes the state of fold. The text stretch S between fold and Matching(fold) is replaced by the text HiddenText(fold). The stretch S will be the new hidden text.
  219. 20        fold # NIL
  220. (Matching(fold) # NIL) & (fold.state' = collapsed)
  221.     fold.state = expanded
  222. (Matching(fold) # NIL) & (fold.state' = expanded)
  223.     fold.state = collapsed
  224. Matching(fold) = NIL
  225.     no effect
  226. PROCEDURE FlipNested (fold: Fold)
  227. Changes the state of fold, and all fold views f between fold and Matching(fold) for which f.state = fold.state.
  228. 20        fold # NIL
  229. (Matching(fold) # NIL) & (fold.state' = collapsed)
  230.     fold.state = expanded
  231.     For all folds f between fold and Matching(fold): f.state = expanded
  232. (Matching(fold) # NIL) & (fold.state' = expanded)
  233.     fold.state = collapsed
  234.     For all folds f between fold and Matching(fold): f.state = collapsed
  235. Matching(fold) = NIL
  236.     no effect
  237. PROCEDURE CollapseFolds (text: TextModels.Model; nested: BOOLEAN;
  238.                                                         label: ARRAY OF CHAR)
  239. If nested holds and label = "", all folds f in text with f.state = expanded are flipped. If ~nested, only the outermost folds in the nesting hierarchy are flipped. If label # "", only folds with f.label = label are flipped.
  240. 20        text # NIL
  241. PROCEDURE ExpandFolds (text: TextModels.Model; nested: BOOLEAN; label: ARRAY OF CHAR);
  242. If nested holds and label = "", all folds f in text with f.state = collapsed are flipped. If ~nested, only the outermost folds in the nesting hierarchy are flipped. If label # "", only folds with f.label = label are flipped.
  243. 20        text # NIL
  244. PROCEDURE Collapse
  245. Collapse all fold views in the focus text.
  246. PROCEDURE Expand
  247. Expand all fold views in the focus text.
  248. PROCEDURE ZoomOut
  249. Collapse all outermost expanded fold views in the focus text.
  250. PROCEDURE ZoomIn
  251. Expand all outermost collapsed views in the focus text.
  252. PROCEDURE CollapseLabel
  253. Bound to the interactor button foldData.expand.
  254. foldData.selective
  255.     CollapseFolds(FocusText, foldData.nested, foldData.label)
  256. ~foldData.selective
  257.     CollapseFolds(FocusText, foldData.nested, "")
  258. PROCEDURE ExpandLabel
  259. Bound to the interactor button foldData.expand.
  260. foldData.selective
  261.     ExpandFolds(FocusText, foldData.nested, foldData.label)
  262. ~foldData.selective
  263.     ExpandFolds(FocusText, foldData.nested, "")
  264. PROCEDURE LabelCheckNotify (op, from, to: LONGINT)
  265. The notifier that is called when the checkbox bound to foldData.selective changes its value.
  266. PROCEDURE LabelGuard (VAR par: Dialog.Par)
  267. The guard bound to the foldData.label text field.
  268. PROCEDURE Overlaps (text: TextModels.Model; beg, end: LONGINT): BOOLEAN;
  269. Returns TRUE if the text stretch [beg, end) in text partially overlaps a pair (f, Matching(f)) of fold views.
  270. 20        text # NIL
  271. 21        (beg >= 0) & (end <= text.Length()) & (beg <= end)
  272. PROCEDURE Insert (text: TextModels.Model; beg, end: LONGINT; state: LONGINT);
  273. Inserts a new pair (f1, f2) of fold views into text. The new pair will bracket the text stretch [beg, end).
  274. 20        text # NIL
  275. 21        (beg >= 0) & (end <= text.Length()) & (beg <= end)
  276. 22        (state = collapsed) OR (state = expanded)
  277. the text stretch [beg, end) does not partially overlap a pair of folds
  278.     Pos(f1) = beg
  279.     Pos(f2) = end+1
  280.     Matching(f1) = f2
  281.     f1.state = f2.state = state
  282.     HiddenText(f1) = NIL
  283. the text stretch [beg, end) partially overlaps a pair of folds
  284.     nothing is done
  285. PROCEDURE CreateGuard (VAR par: Dialog.Par)
  286. Sets par.disabled to TRUE when the text selection in the current focus text partially overlaps a pair (f, Matching(f)) of fold views. par.disabled  is also set to TRUE if the focus text is shown in browser mode or mask mode, that is if the text cannot be modified.
  287. PROCEDURE Create (state: LONGINT)
  288. If CreateGuard holds, creates a a new pair of fold views and inserts them into the focus text, bracketing the current text selection or the caret position. Calls Insert(FocusText, selBeg, selEnd, state).
  289. 20        (state = collapsed) OR (state = expanded)
  290. PROCEDURE Init (fold: Fold; kind, state: INTEGER; label: Label; hidden: TextModels.Model);
  291. Initializes fold with the given values. A possible hidden text is only associated with a left fold view. For a right fold view, hidden must be NIL.
  292. 21        (kind = left) OR (kind = right)
  293. 22        (state = collapsed) OR (state = expanded)
  294. 23        kind = left => hidden = NIL
  295. (fold.kind = kind) & (fold.state = state) & (fold.label = label)
  296. Menu Commands
  297. Recommended use of commands in the menu definition file:
  298.     "Create Fold"    ""    "StdFolds.Create(1)"    "StdFolds.CreateGuard"
  299.     "Expand All"    ""    "StdFolds.Expand"    ""
  300.     "Collapse All"    ""    "StdFolds.Collapse"    ""
  301.     "Fold..."    ""    "StdCmds.OpenToolDialog('StdFolds.foldData', 'Zoom')"    ""
  302.     "Set Label..."    ""    "StdFolds.InitLabelDialog; StdCmds.OpenToolDialog('StdFolds.lblData', 'SetLabel')"    "TextCmds.SelectionGuard"
  303. TextControllers.StdCtrlDesc
  304. TextControllers.ControllerDesc
  305. Helvetica
  306. Documents.ControllerDesc
  307.